package be.ipl.jack.domaine;

import java.io.Serializable;
import java.util.Random;

import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

@SuppressWarnings("serial")
@Entity
@Table(name="DES", schema="JACK")
public class De implements Serializable{
	
	@Id @GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(name = "ID")
	private int id;
	
	@NotNull
	private int numero;
	
	@NotNull
	@Min(1)
	@Max(6)
	private int valeur;
	
	@NotNull
	private boolean ecarte;
	
	@Transient  // on le garde pas en DB
	private Random lance = new Random();
	
	public De() {
		
	}	
	
	public De(int numero) {
		super();
		this.numero = numero;
		this.valeur = 1;
	}

	public int lancerDe() {		
		int val = 1;
		valeur = val;
		return val;
	}

	public int getId() {
		return id;
	}

	public int getNumero() {
		return numero;
	}

	public int getValeur() {
		return valeur;
	}	

	public boolean isEcarte() {
		return ecarte;
	}

	public Random getLance() {
		return lance;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + id;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		De other = (De) obj;
		if (id != other.id)
			return false;
		return true;
	}	
}
